{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def canConstruct(self, ransomNote, magazine):\n",
    "        \"\"\"\n",
    "        :type ransomNote: str\n",
    "        :type magazine: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        ransomNote = list(ransomNote)\n",
    "        ransomNote.sort()\n",
    "        \n",
    "        magazine = list(magazine)\n",
    "        magazine.sort()\n",
    "        magazine = ''.join(magazine)\n",
    "        \n",
    "        for ch in ransomNote:\n",
    "            if ch in magazine:\n",
    "                magazine = magazine.replace(ch, '', 1)\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.canConstruct(\"bg\",\"efjbdfbdgfjhhaiigfhbaejahgfbbgbjagbddfgdiaigdadhcfcj\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
